<?php
/**
 * Created by PhpStorm.
 * User: Janpoem
 * Date: 2015/3/9
 * Time: 2:36
 *
 * 该文件仅用于测试使用，不应该用于实际环境
 */

defined('AUTOLOAD_CLASS') || define('AUTOLOAD_CLASS', true, true);

class SimpleAutoLoad
{

    protected static $classes = array();

    public static function registerClasses(array $classes)
    {
        static::$classes += $classes;
    }

    public static function registerFile($path)
    {
        if (is_file($path) && is_readable($path)) {
            $classes = require $path;
            if (!empty($classes) && is_array($classes))
                static::registerClasses($classes);
        }
    }

    public static function loadClass($class)
    {
//        var_dump($class);
        if (isset(static::$classes[$class]))
            require static::$classes[$class] . '.php';
    }
}

if (AUTOLOAD_CLASS) {
    SimpleAutoLoad::registerFile(__DIR__ . '/classes.php');
}

spl_autoload_register(array('SimpleAutoLoad', 'loadClass'));
